<template>
  <div class="view_page empowerlist">
    <el-card class="box-card">
      <!--卡片头部-->
      <div slot="header" class="clearfix">
        <!--左侧-->
        <div class="left">
          <div class="menu-title">
            设备信息
          </div>
        </div>
        <!-- <div class="right">
        </div> -->
      </div>
      <!--筛选-->
      <div class="query-operate">
        <el-form
          class="demo-form-inline indoor-scene-buzhou-list-form"
          :inline="true"
          :model="TESTFROMDATA"
          @submit.native.prevent
        >
          <el-form-item
            label="气泡名称"
            label-width="120px"
            style="margin-top: 5px; margin-bottom: 5px;"
          >
            <el-input
              clearable
              @clear="searchList"
              v-model="TESTFROMDATA.name"
              placeholder="请输入气泡名称"
              @keyup.native.enter="searchList()"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="工程ID"
            label-width="70px"
            style="margin-top: 5px; margin-bottom: 5px;"
          >
            <el-input
              clearable
              @clear="searchList"
              v-model="TESTFROMDATA.project_id"
              placeholder="请输入工程ID"
              @keyup.native.enter="searchList()"
            ></el-input>
          </el-form-item>

          <el-form-item
            style="margin-top: 5px; margin-bottom: 5px;margin-left: 10px;"
          >
            <el-button type="primary" @click="searchList()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!--卡片内容-->
      <!--列表-->
      <el-table :data="datalist" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" align="center">
        </el-table-column>
        <!-- <el-table-column
          prop="name"
          label="气泡名称"
          align="left"
          min-width="140"
        >
        </el-table-column> -->

        <el-table-column
          prop="name"
          label="气泡名称"
          min-width="140"
          align="left"
        >
          <template slot-scope="scope">
            <el-popover
              width="500"
              trigger="hover"
              placement="top"
              v-if="scope.row.name.length > 8"
            >
              <p>{{ scope.row.name }}</p>
              <div slot="reference" class="name-wrapper">
                <div class="list-name">{{ scope.row.name }}</div>
              </div>
            </el-popover>
            <div class="list-name" v-if="scope.row.name.length < 9">
              {{ scope.row.name }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="projectId"
          label="工程ID"
          width="80"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="equipmentType"
          label="设备类型"
          align="center"
          min-width="140"
        >
        </el-table-column>
        <el-table-column
          prop="modelId"
          label="展示模型ID"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="infoUrl"
          label="展示模型url"
          min-width="280"
          align="left"
        >
          <template slot-scope="scope">
            <el-popover
              width="500"
              trigger="hover"
              placement="top"
              v-if="scope.row.infoUrl.length > 19"
            >
              <p>{{ scope.row.infoUrl }}</p>
              <div slot="reference" class="name-wrapper">
                <div class="list-name">{{ scope.row.infoUrl }}</div>
              </div>
            </el-popover>
            <div class="list-name" v-if="scope.row.infoUrl.length < 20">
              {{ scope.row.infoUrl }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          prop="infoUrl"
          label="复制url"
          align="left"
          min-width="80"
        >
          <template slot-scope="scope">
            <i
              style="margin-left:10px;cursor: pointer"
              class="el-icon-document-copy"
              v-clipboard:copy="scope.row.infoUrl"
              v-clipboard:success="onCopy"
            ></i>
          </template>
        </el-table-column> -->

        <el-table-column
          prop="posX"
          label="气泡X轴位置"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="posY"
          label="气泡Y轴位置"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="posZ"
          label="气泡Z轴位置"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="focusingX"
          label="聚焦气泡X值"
          align="center"
          min-width="100"
        >
        </el-table-column
        ><el-table-column
          prop="focusingY"
          label="聚焦气泡Y值"
          align="center"
          min-width="100"
        >
        </el-table-column
        ><el-table-column
          prop="focusingDistance"
          label="气泡距离"
          align="center"
          min-width="100"
        >
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="160" align="center">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;flex-wrap: wrap; ">
              <el-button
                type="primary"
                size="small"
                @click="navtoAdd(scope.row.id)"
                >修改
              </el-button>
              <el-button
                type="success"
                size="small"
                @click="lookfiles(scope.row)"
                >查看url
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <pagination
        :total="total"
        :currentPage="pageNum"
        :pageSize="size"
        position="right"
        @search="searchPagination"
      >
      </pagination>
    </el-card>

    <!--新增修改弹框-->
    <el-dialog title="修改设备信息" :visible.sync="dialogVisible" width="40%">
      <el-form ref="form" label-width="120px">
        <el-form-item label="设备类型">
          <el-input
            v-model="liveData.equipmentType"
            clearable
            placeholder="请输入设备类型"
          ></el-input>
        </el-form-item>
        <el-form-item label="展示模型ID">
          <el-input
            v-model="liveData.modelId"
            clearable
            placeholder="请输入展示模型ID"
          ></el-input>
        </el-form-item>
        <el-form-item label="展示模型url">
          <el-input
            v-model="liveData.infoUrl"
            clearable
            placeholder="请输入展示模型url"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from "element-ui";
import pagination from "@/components/common/pagination/pagination";

export default {
  components: {
    pagination
  },
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("loginPersonnelInformation")),
      // 模糊查询数据
      TESTFROMDATA: {
        name: "",
        project_id: ""
      },
      // 列表的数据
      datalist: [],
      pageNum: 1,
      page: 1,
      size: 10,
      total: 0,

      // 弹窗
      dialogVisible: false,
      itemID: "", //记录选中的id

      //富文本文档类型
      liveData: {
        equipmentType: "",
        modelId: "",
        infoUrl: ""
      }
    };
  },
  created() {
    var _this = this;
    _this.getListPage();
  },
  mounted() {},
  methods: {
    initData() {
      this.liveData = {
        equipmentType: "",
        modelId: "",
        infoUrl: ""
      };
    },
    //查询测点列表
    getListPage() {
      var _this = this;
      var datas = {
        name: _this.TESTFROMDATA.name,
        project_id: _this.TESTFROMDATA.project_id,
        page: _this.page,
        size: _this.size
      };
      _this.$apis.bubble_device_list(datas).then(res => {
        if (res.result == 0) {
          _this.datalist = res.data;
          _this.total = res.rows;
          _this.pageNum = res.page;
        }
      });
    },

    //模糊查询
    searchList() {
      this.page = 1;
      this.datalist = [];
      this.getListPage();
    },
    //分页
    searchPagination(page) {
      this.page = page;
      // localStorage.setItem("page", page);
      this.getListPage();
    },
    onCopy() {
      Message.success("复制成功");
    },
    // 打开弹窗
    navtoAdd(item) {
      var _this = this;
      _this.initData();

      _this.itemID = item;
      var datas = {
        id: _this.itemID
      };
      // 查询详情
      _this.$apis.bubble_device_query(datas).then(res => {
        if (res.result == 0) {
          _this.liveData = res.data;
        }
        _this.dialogVisible = true;
      });
    },
    //取消
    cancel() {
      this.dialogVisible = false;
    },
    save() {
      var _this = this;
      var datas = _this.liveData;
      // var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
      var reg = /^((https?|ftp):\/\/)?([\da-z.-]+)\.([a-z.]{2,6})(\/\w\.-]*)*\/?/;
      if (datas.equipmentType == "") {
        Message.error("请填写设备类型");
        return;
      }
      if (datas.modelId == "") {
        Message.error("请填写展示模型ID");
        return;
      }
      if (datas.infoUrl == "") {
        Message.error("请填写展示模型url");
        return;
      }
      if (!reg.test(datas.infoUrl)) {
        Message.error("请填写正确格式的url地址");
        return;
      }

      datas.id = _this.itemID;
      _this.$apis.bubble_device_update(datas).then(res => {
        if (res.result == 0) {
          Message.success("修改成功");
          this.dialogVisible = false;
          this.getListPage();
        } else {
          this.dialogVisible = false;
          this.getListPage();
        }
      });
    },
    lookfiles(item) {
      window.open(item.infoUrl);
    }
  }
};
</script>

<style>
.empowerlist .el-dialog__header {
  border-bottom: 1px solid #e3e3e3;
}
.column-bz {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.empower-time {
  width: 100% !important;
}
/**站内信长单词强制换行 */
.message_box_alert {
  word-break: break-all !important;
}
.key-content .el-form-item__content {
  margin-left: 0 !important;
}
</style>
